package influxdb

import (
	"github.com/influxdata/influxdb/client/v2"
	"log"
	"time"
)

const (
	Wifidetectorigdata          = "wifidetectorigdata"
	Wifidetectorigdata_business = "wifidetectorigdata_business"
)

type WifiDetector struct {
	Time            time.Time
	ZoneId          string
	Index           string
	Ipaddr          string
	Macdetected     string
	Enter           int
	Rssi            int
	Type            int
	Macorganization string
}

func (c *Connect) InsertWifiDetector(wifi *[]*WifiDetector, tableName string) int {
	var cPoint []*client.Point
	for _, value := range *wifi {
		tags := map[string]string{
			"zoneid": value.ZoneId,
			"index":  value.Index,
		}
		fields := map[string]interface{}{
			"ipaddr":          value.Ipaddr,
			"macdetected":     value.Macdetected,
			"enter":           value.Enter,
			"rssi":            value.Rssi,
			"type":            value.Type,
			"macorganization": value.Macorganization,
		}
		pt, err := client.NewPoint(tableName, tags, fields, value.Time)
		if err != nil {
			log.Println(err)
			return -1
		} else {
			cPoint = append(cPoint, pt)
		}
	}
	return c.insert(50000, cPoint)
}
